<!--
 * @Descripttion: (OP80钎焊记录/dc_op80_record)
 * @Author: (admin)
 * @Date: (2025-02-28)
-->
<template>
    <div>
      <el-form :model="queryParams" label-position="right" inline ref="queryRef" v-show="showSearch" @submit.prevent>
        <el-form-item>
          <el-button icon="search" type="primary" @click="handleQuery">{{ $t('btn.search') }}</el-button>
          <el-button icon="refresh" @click="resetQuery">{{ $t('btn.reset') }}</el-button>
        </el-form-item>
      </el-form>
      <!-- 工具区域 -->
      <el-row :gutter="15" class="mb10">
        <el-col :span="1.5">
          <!-- <el-button type="primary" v-hasPermi="['dcop80record:add']" plain icon="plus" @click="handleAdd">
            {{ $t('btn.add') }}
          </el-button> -->
        </el-col>
        <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
      </el-row>
  
      <el-table
        :data="dataList"
        v-loading="loading"
        ref="table"
        border
        header-cell-class-name="el-table-header-cell"
        highlight-current-row
        @sort-change="sortChange"
        >
        <el-table-column prop="id" label="Id" align="center" v-if="columns.showColumn('id')"/>
        <el-table-column :render-header="renderHeader" prop="fixtureId" label="夹具号" align="center" v-if="columns.showColumn('fixtureId')"/>
        <el-table-column :render-header="renderHeader" prop="coverCode" label="盖板码" align="center" :show-overflow-tooltip="true" v-if="columns.showColumn('coverCode')"/>
        <el-table-column :render-header="renderHeader" prop="flatnessCheckResult" label="平面度检测结果" align="center" v-if="columns.showColumn('flatnessCheckResult')"/>
        <el-table-column width="100" :render-header="renderHeader" prop="flatness" label="平面度" align="center" v-if="columns.showColumn('flatness')"/>
        <el-table-column width="180" prop="moldRemovalTime" label="拆模时间" :show-overflow-tooltip="true"  v-if="columns.showColumn('moldRemovalTime')"/>
        <el-table-column width="180" prop="brazingTime" label="钎焊时间	" :show-overflow-tooltip="true"  v-if="columns.showColumn('brazingTime')"/>
        <el-table-column :render-header="renderHeader" prop="inspectionResult1" label="InspectionResult1" align="center" v-if="columns.showColumn('inspectionResult1')"/>
        <el-table-column :render-header="renderHeader" prop="inspectionResult2" label="InspectionResult2" align="center" v-if="columns.showColumn('inspectionResult2')"/>
        <el-table-column :render-header="renderHeader" prop="inspectionResult3" label="InspectionResult3" align="center" v-if="columns.showColumn('inspectionResult3')"/>
        <el-table-column :render-header="renderHeader" prop="inspectionResult4" label="InspectionResult4" align="center" v-if="columns.showColumn('inspectionResult4')"/>
        <el-table-column :render-header="renderHeader" prop="inspectionResult5" label="InspectionResult5" align="center" v-if="columns.showColumn('inspectionResult5')"/>
        <el-table-column :render-header="renderHeader" prop="inspectionResult6" label="InspectionResult6" align="center" v-if="columns.showColumn('inspectionResult6')"/>
        <el-table-column :render-header="renderHeader" prop="inspectionResult7" label="InspectionResult7" align="center" v-if="columns.showColumn('inspectionResult7')"/>
        <el-table-column :render-header="renderHeader" prop="inspectionResult8" label="InspectionResult8" align="center" v-if="columns.showColumn('inspectionResult8')"/>
        <el-table-column width="180" prop="createdTime" label="创建时间" :show-overflow-tooltip="true"  v-if="columns.showColumn('createdTime')"/>
        <!-- <el-table-column label="操作" width="160">
          <template #default="scope">
            <el-button type="success" size="small" icon="edit" title="编辑" v-hasPermi="['dcop80record:edit']" @click="handleUpdate(scope.row)"></el-button>
            <el-button type="danger" size="small" icon="delete" title="删除" v-hasPermi="['dcop80record:delete']" @click="handleDelete(scope.row)"></el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  
  
      <!-- 添加或修改OP80钎焊记录对话框 -->
      <el-dialog :title="title" :lock-scroll="false" v-model="open" >
        <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
          <el-row :gutter="20">
              
            <el-col :lg="12" v-if="opertype != 1">
              <el-form-item label="Id" prop="id">
                <el-input-number v-model.number="form.id" controls-position="right" placeholder="请输入Id" :disabled="true"/>
              </el-form-item>
            </el-col>
              
            <el-col :lg="12">
              <el-form-item label="夹具号" prop="fixtureId">
                <el-input v-model.number="form.fixtureId" placeholder="请输入夹具号" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="盖板码" prop="coverCode">
                <el-input v-model="form.coverCode" placeholder="请输入盖板码" />
              </el-form-item>
            </el-col>
              
            <el-col :lg="12">
              <el-form-item label="平面度检测结果" prop="flatnessCheckResult">
                <el-input v-model.number="form.flatnessCheckResult" placeholder="请输入平面度检测结果" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="平面度" prop="flatness">
                <el-input v-model="form.flatness" placeholder="请输入平面度" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="拆模时间" prop="moldRemovalTime">
                <el-date-picker v-model="form.moldRemovalTime" type="datetime" :teleported="false" placeholder="选择日期时间"></el-date-picker>
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="钎焊时间	" prop="brazingTime">
                <el-date-picker v-model="form.brazingTime" type="datetime" :teleported="false" placeholder="选择日期时间"></el-date-picker>
              </el-form-item>
            </el-col>
              
            <el-col :lg="12">
              <el-form-item label="8个检测结果" prop="inspectionResult1">
                <el-input v-model.number="form.inspectionResult1" placeholder="请输入8个检测结果" />
              </el-form-item>
            </el-col>
              
            <el-col :lg="12">
              <el-form-item label="InspectionResult2" prop="inspectionResult2">
                <el-input v-model.number="form.inspectionResult2" placeholder="请输入InspectionResult2" />
              </el-form-item>
            </el-col>
              
            <el-col :lg="12">
              <el-form-item label="InspectionResult3" prop="inspectionResult3">
                <el-input v-model.number="form.inspectionResult3" placeholder="请输入InspectionResult3" />
              </el-form-item>
            </el-col>
              
            <el-col :lg="12">
              <el-form-item label="InspectionResult4" prop="inspectionResult4">
                <el-input v-model.number="form.inspectionResult4" placeholder="请输入InspectionResult4" />
              </el-form-item>
            </el-col>
              
            <el-col :lg="12">
              <el-form-item label="InspectionResult5" prop="inspectionResult5">
                <el-input v-model.number="form.inspectionResult5" placeholder="请输入InspectionResult5" />
              </el-form-item>
            </el-col>
              
            <el-col :lg="12">
              <el-form-item label="InspectionResult6" prop="inspectionResult6">
                <el-input v-model.number="form.inspectionResult6" placeholder="请输入InspectionResult6" />
              </el-form-item>
            </el-col>
              
            <el-col :lg="12">
              <el-form-item label="InspectionResult7" prop="inspectionResult7">
                <el-input v-model.number="form.inspectionResult7" placeholder="请输入InspectionResult7" />
              </el-form-item>
            </el-col>
              
            <el-col :lg="12">
              <el-form-item label="InspectionResult8" prop="inspectionResult8">
                <el-input v-model.number="form.inspectionResult8" placeholder="请输入InspectionResult8" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="修改时间" prop="updateTime">
                <el-date-picker v-model="form.updateTime" type="datetime" :teleported="false" placeholder="选择日期时间"></el-date-picker>
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="创建时间" prop="createdTime">
                <el-date-picker v-model="form.createdTime" type="datetime" :teleported="false" placeholder="选择日期时间"></el-date-picker>
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="IsDeleted" prop="isDeleted">
                <el-radio-group v-model="form.isDeleted">
                  <el-radio v-for="item in options.isDeletedOptions" :key="item.dictValue" :value="item.dictValue">
                    {{item.dictLabel}}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <template #footer v-if="opertype != 3">
          <el-button text @click="cancel">{{ $t('btn.cancel') }}</el-button>
          <el-button type="primary" @click="submitForm">{{ $t('btn.submit') }}</el-button>
        </template>
      </el-dialog>
    </div>
  </template>
  
  <script setup name="dcop80record">
  import { listDcOp80Record,
   addDcOp80Record, delDcOp80Record, 
   updateDcOp80Record,getDcOp80Record, 
   } 
  from '@/api/business/dcop80record.js'
  const { proxy } = getCurrentInstance()
  const ids = ref([])
  const loading = ref(false)
  const showSearch = ref(true)
  const queryParams = reactive({
    pageNum: 1,
    pageSize: 10,
    sort: 'Id',
    sortType: 'desc',
  })
  const columns = ref([
    { visible: true, prop: 'id', label: 'Id' },
    { visible: true, prop: 'fixtureId', label: '夹具号' },
    { visible: true, prop: 'coverCode', label: '盖板码' },
    { visible: true, prop: 'flatnessCheckResult', label: '平面度检测结果' },
    { visible: true, prop: 'flatness', label: '平面度' },
    { visible: true, prop: 'moldRemovalTime', label: '拆模时间' },
    { visible: true, prop: 'brazingTime', label: '钎焊时间	' },
    { visible: true, prop: 'inspectionResult1', label: 'inspectionResult1' },
    { visible: true, prop: 'inspectionResult2', label: 'InspectionResult2' },
    { visible: true, prop: 'inspectionResult3', label: 'InspectionResult3' },
    { visible: true, prop: 'inspectionResult4', label: 'InspectionResult4' },
    { visible: true, prop: 'inspectionResult5', label: 'InspectionResult5' },
    { visible: true, prop: 'inspectionResult6', label: 'InspectionResult6' },
    { visible: true, prop: 'inspectionResult7', label: 'InspectionResult7' },
    { visible: true, prop: 'inspectionResult8', label: 'InspectionResult8' },
    { visible: true, prop: 'createdTime', label: '创建时间' },
  ])
  const total = ref(0)
  const dataList = ref([])
  const queryRef = ref()
  const defaultTime = ref([new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)])
  
  
  var dictParams = [
  ]
  
  
  const renderHeader = ({ column }) => {
    //创建一个元素用于存放表头信息
    const span = document.createElement('span')
    // 将表头信息渲染到元素上
    span.innerText = column.label
    // 在界面中添加该元素
    document.body.appendChild(span)
    //获取该元素的宽度（包含内外边距等信息）
    const spanWidth = span.getBoundingClientRect().width + 20  //渲染后的 div 内左右 padding 都是 10，所以 +20
    //判断是否小于element的最小宽度，两者取最大值
    column.minWidth = column.minWidth > spanWidth ? column.minWidth : spanWidth
    // 计算完成后，删除该元素
    document.body.removeChild(span)
    return column.label
}


  function getList(){
    loading.value = true
    listDcOp80Record(queryParams).then(res => {
      const { code, data } = res
      if (code == 200) {
        dataList.value = data.result
        total.value = data.totalNum
        loading.value = false
      }
    })
  }
  
  // 查询
  function handleQuery() {
    queryParams.pageNum = 1
    getList()
  }
  
  // 重置查询操作
  function resetQuery(){
    proxy.resetForm("queryRef")
    handleQuery()
  }
  // 自定义排序
  function sortChange(column) {
    var sort = undefined
    var sortType = undefined
  
    if (column.prop != null && column.order != null) {
      sort = column.prop
      sortType = column.order
  
    }
    queryParams.sort = sort
    queryParams.sortType = sortType
    handleQuery()
  }
  
  /*************** form操作 ***************/
  const formRef = ref()
  const title = ref('')
  // 操作类型 1、add 2、edit 3、view
  const opertype = ref(0)
  const open = ref(false)
  const state = reactive({
    single: true,
    multiple: true,
    form: {},
    rules: {
      createdTime: [{ required: true, message: "创建时间不能为空", trigger: "blur"     }],
      isDeleted: [{ required: true, message: "IsDeleted不能为空", trigger: "blur"     }],
    },
    options: {
      // IsDeleted 选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'}
  isDeletedOptions: [],
    }
  })
  
  const { form, rules, options, single, multiple } = toRefs(state)
  
  // 关闭dialog
  function cancel(){
    open.value = false
    reset()
  }
  
  // 重置表单
  function reset() {
    form.value = {
      id: null,
      fixtureId: null,
      coverCode: null,
      flatnessCheckResult: null,
      flatness: null,
      moldRemovalTime: null,
      brazingTime: null,
      inspectionResult1: null,
      inspectionResult2: null,
      inspectionResult3: null,
      inspectionResult4: null,
      inspectionResult5: null,
      inspectionResult6: null,
      inspectionResult7: null,
      inspectionResult8: null,
      updateTime: null,
      createdTime: null,
      isDeleted: null,
    };
    proxy.resetForm("formRef")
  }
  
  
  // 添加按钮操作
  function handleAdd() {
    reset();
    open.value = true
    title.value = '添加OP80钎焊记录'
    opertype.value = 1
  }
  // 修改按钮操作
  function handleUpdate(row) {
    reset()
    const id = row.id || ids.value
    getDcOp80Record(id).then((res) => {
      const { code, data } = res
      if (code == 200) {
        open.value = true
        title.value = '修改OP80钎焊记录'
        opertype.value = 2
  
        form.value = {
          ...data,
        }
      }
    })
  }
  
  // 添加&修改 表单提交
  function submitForm() {
    proxy.$refs["formRef"].validate((valid) => {
      if (valid) {
  
        if (form.value.id != undefined && opertype.value === 2) {
          updateDcOp80Record(form.value).then((res) => {
            proxy.$modal.msgSuccess("修改成功")
            open.value = false
            getList()
          })
        } else {
          addDcOp80Record(form.value).then((res) => {
              proxy.$modal.msgSuccess("新增成功")
              open.value = false
              getList()
            })
        }
      }
    })
  }
  
  // 删除按钮操作
  function handleDelete(row) {
    const Ids = row.id || ids.value
  
    proxy
      .$confirm('是否确认删除参数编号为"' + Ids + '"的数据项？', "警告", {
        confirmButtonText: proxy.$t('common.ok'),
        cancelButtonText: proxy.$t('common.cancel'),
        type: "warning",
      })
      .then(function () {
        return delDcOp80Record(Ids)
      })
      .then(() => {
        getList()
        proxy.$modal.msgSuccess("删除成功")
      })
  }
  
  
  
  
  
  handleQuery()
  </script>

<style scoped>

</style>